(function($, doc) {
	mui.init();
	/*
	function defaultImg() {

		if(mui.os.plus) {
			plus.io.resolveLocalFileSystemURL("_doc/head.jpg", function(entry) {
				var s = entry.fullPath + "?version=" + new Date().getTime();;
				document.getElementById("head-img").src = s;
			}, function(e) {
				document.getElementById("head-img").src = 'static/images/logo.png';
			})
		} else {
			document.getElementById("head-img").src = 'static/images/logo.png';
		}
	}*/
	mui.plusReady(function() {
		var userinfo = app.getState();
		var myWallet = ethscan.getWallet('eth');

		//var avatar = serverurl + 'upload/avatar/' + userinfo.user_id + '.jpg';
		//console.log(avatar);
		//userinfo.avatar = avatar;
		//console.log(myWallet.address);
		//console.log(sysethaddr);
		if(myWallet.address == sysethaddr) {
			document.getElementById('sysmgrlist').style.display = '';
		}
		//		if(avatar && avatar.indexOf('upload') !== -1) {
		//			avatar = serverurl + 'upload/avatar/' + userinfo.user_id + '.jpg';
		//		}else{
		//			avatar = 'static/images/1.png';
		//		}
		//userinfo.avatar = serverurl + avatar;
		//userinfo.avatar = app.avatar(userinfo.user_id, 'static/images/1.png');
		//userinfo.avatar = avatar;
		// alert(avatar);
		// var img1 = '../../static/images/1.png';
		// var img2 = 'upload/avatar/' + uid + '.jpg';
		document.querySelector("#me-area").innerHTML = template('me-templete', {
			"user": userinfo
		});
		//document.getElementById("head-img").src = serverurl + avatar;
		mui("#mehrefs").on("tap", "a", function() {

			var targets = this.getAttribute("href") + "?user_id=" + userinfo.user_id;
			var id = this.getAttribute("href");
			if(this.getAttribute("href") == 'login.html') {
				app.out();
				plus.runtime.restart();
			} else if(this.getAttribute("href") == 'pages/friends/profile.html') {
				mui.openWindow({
					url: "pages/friends/profile.html",
					id: "profile",
					extras: {
						u_id: app.getState().user_id,
						head_img: app.getState().avatar,
						name: app.getState().name
					}
				});
			} else if(this.getAttribute("href") == 'pages/coin/mgrcharge.html') {
				///plus.runtime.openURL('https://diamondplanets.com/Wap/index/login.html');
				var type = this.getAttribute('data-type');
				mui.openWindow({
					url: "pages/coin/mgrcharge.html",
					id: "mgrcharge",
					extras: {
						type: type
					}
				});

			}  else if(this.getAttribute("href") == 'pages/coin/chksale.html') {
				///plus.runtime.openURL('https://diamondplanets.com/Wap/index/login.html');
				var type = this.getAttribute('data-type');
				mui.openWindow({
					url: "pages/coin/chksale.html",
					id: "chksale",
					extras: {
						type: type
					}
				});

			} else if(this.getAttribute("href") == 'tuiguang.html') {
				mui.openWindow({
					url: "pages/opwin/tuiguang.html",
					id: "tuiguang",
					extras: {
						u_id: app.getState().user_id,
						postpas: md5(app.getState().password),
						lang: plus.os.language
					}
				});
			} else if(this.getAttribute("href") == 'paymerchant.html') {
				mui.openWindow({
					url: "pages/opwin/paymerchant.html",
					id: "tuiguang",
					extras: {
						u_id: app.getState().user_id,
						postpas: md5(app.getState().password),
						lang: plus.os.language
					}
				});
			} else if(this.getAttribute("href") == 'opgatc.html') {
				//var postpas = md5(app.getState().password);
				mui.openWindow({
					url: "pages/opwin/opgatc.html",
					id: "opgatc",
					extras: {
						u_id: app.getState().user_id,
						postpas: md5(app.getState().password),
						lang: plus.os.language
					}
				});

			} else if(this.getAttribute("href") == 'https://fatcat-dev.1a2b333.com/app/fatcat/fatcat.apk') {
				plus.runtime.openURL('https://fatcat-dev.1a2b333.com/app/fatcat/fatcat.apk');
			} else if(this.getAttribute("href") == '#') {
				plus.nativeUI.alert('开发中！');
			}
			//plus.runtime.openURL
			else {
				//location.href = targets;
				mui.openWindow({
					url: targets,
					id: id
				})
			}

			/*
			mui.openWindow({
				url: targets,
				id: targets
			});*/
		});
		doc.addEventListener('refresh', function(event) {
			var userinfo = app.getState();
			//userinfo.avatar = app.avatar(userinfo.user_id, 'static/images/1.png');
			document.getElementById("head-img").src = userinfo.avatar;
			//console.log(serverurl + userinfo.avatar);

		});
		/*
		var mainid = localStorage.getItem('mainpage');
		var mainWin = plus.webview.getWebviewById(mainid);
		doc.addEventListener('swipeleft', function(event) {
			var angle = event.detail.angle;
			angle = Math.abs(angle);
			if(angle > 165 && angle < 195) {
			mui.fire(mainWin, 'swipe_event', {
				target: 'chat.html'
			});
			}
		});
		doc.addEventListener('swiperight', function(event) {
			if(Math.abs(event.detail.angle) < 30) {
			mui.fire(mainWin, 'swipe_event', {
				target: 'find.html'
			});
			}
		});*/
		//defaultImg();
	});
}(mui, document));